#define quickread
#ifdef quickread
#include <cstdio> 
template <typename T>
inline void read(T& x)
{
    int c=getchar(), f=1; x=0;
    while(c<'0'||'9'<c) {if(c=='-') f=-1; c=getchar();}
    while('0'<=c&&c<='9') 
        x=(x<<3)+(x<<1)+c-'0', c=getchar();
    x*=f;
}
template <typename T>
inline void quickwrite(T x)
{
    if(x<0) putchar('-'), x*=-1;
    if(x>=10) quickwrite(x/10);
    putchar(x%10+'0');
}
#else 
#include <iostream>
#endif
using namespace std;
#define DEBUG
const int N=1e6+10, mod=1e9+7;
int n, m, vis[N], tree[N], res[N];
void init()
{

}

void solve(){
    cin >>n >> m;
    for(lli=1;i<=n; i++)
    {
        cin >>a[i].x; 
        a[i].old =i;
    }
    for(ll i=1; i<=m; i++)
    { 
        cin >> q[i].l >> q[i].r >> q[i].x; q[i].old=i;
    }
    sort(a+1，a+1+n,cmp2);
    sort(q+1，q+1+m，cmp1);
    ll id = n;
    for(lli=1;i<= m; i++)
    {
        if(!vis[q[i].x])
        {
            vis[q[i].x]= 1;
            while(id >=1&& a[id].x>= q[i].x)
            {
                update(a[id].old，1);id--;
res[q[i].old]= ask(q[i].r)-ask(q[i].1 - 1);for(lli=1;i<=m;i++){cout<<res[i]<< endl;}

// #undef DEBUG
signed main()
{
    #ifdef DEBUG
        freopen("../in.txt", "r", stdin);
        freopen("../out.txt", "w", stdout);
    #endif
    #ifndef quickread
    ios::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    #endif

    int T=1; //scanf("%d", &T);
    while(T--) 
    {
        solve();
    }
    return 0;
}
